package org.e_gold.model.crawler.livescore;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.e_gold.model.ValueObject;

import com.google.gson.annotations.Expose;

/**
 * @author Thang Nguyen
 */
@Entity
@Table(name = "league")
public class League extends ValueObject implements Serializable, Comparable<League>{

	private static final long	serialVersionUID	= 1L;

	@Id
	@GeneratedValue
	@Expose
	private Long id;

	@Column(name="name")
	@Expose
	private String name;

	@ManyToOne()
	@JoinColumn(name="country_id")
	@Expose
	private Country country;

	@OneToMany
	private Set<CEvent> cEvents = new HashSet<CEvent>(0);

	private boolean status = false;

	public boolean isStatus() {
		return status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	public League(){
		this("", null);
	}

	public League(String name){
		this(name, null);
	}

	public League(String name, Country country){
		this.name = name;
		this.country = country;
	}

	@Override
	public int compareTo(League o) {
		int i = name.compareTo(o.getName());
		if(i != 0){
			return i;
		}

		return country.compareTo(o.getCountry());
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((country == null) ? 0 : country.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof League)) {
			return false;
		}
		League other = (League) obj;
		if (country == null) {
			if (other.country != null) {
				return false;
			}
		} else if (!country.equals(other.country)) {
			return false;
		}
		if (name == null) {
			if (other.name != null) {
				return false;
			}
		} else if (!name.equals(other.name)) {
			return false;
		}
		return true;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Country getCountry() {
		return country;
	}

	public void setCountry(Country country) {
		this.country = country;
	}
}
